package com.caiyigo.baihua.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.caiyigo.baihua.dao.XueshengMapper;
import com.caiyigo.baihua.dao.XueshengMapperSql;
import com.caiyigo.baihua.dto.XueshengDto;
import com.caiyigo.baihua.model.Xuesheng;
import com.caiyigo.baihua.service.XueshengService;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;

/**
 * @author Administrator
 *
 */
@Transactional
@Service
public class XueshengServiceImpl implements XueshengService {
	@Resource(name = "xueshengMapper")
	XueshengMapper xueshengMapper;
	@Resource(name = "xueshengMapperSql")
	XueshengMapperSql xueshengMapperSql;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#deleteByPrimaryKey(java.lang.
	 * Integer)
	 */
	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return xueshengMapper.deleteByPrimaryKey(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#insert(com.caiyigo.zoo.model.
	 * Xuesheng)
	 */
	@Override
	public int insert(Xuesheng record) {
		// TODO Auto-generated method stub
		return xueshengMapper.insert(record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#insertSelective(com.caiyigo.zoo
	 * .model.Xuesheng)
	 */
	@Override
	public int insertSelective(Xuesheng record) {
		// TODO Auto-generated method stub
		return xueshengMapper.insertSelective(record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#selectByPrimaryKey(java.lang.
	 * Integer)
	 */
	@Override
	public Xuesheng selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return xueshengMapper.selectByPrimaryKey(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#updateByPrimaryKeySelective(com
	 * .caiyigo.zoo.model.Xuesheng)
	 */
	@Override
	public int updateByPrimaryKeySelective(Xuesheng record) {
		// TODO Auto-generated method stub
		return xueshengMapper.updateByPrimaryKeySelective(record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#updateByPrimaryKey(com.caiyigo
	 * .zoo.model.Xuesheng)
	 */
	@Override
	public int updateByPrimaryKey(Xuesheng record) {
		// TODO Auto-generated method stub
		return xueshengMapper.updateByPrimaryKey(record);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#getUserList(com.caiyigo.zoo.dto
	 * .UserDto, com.github.miemiedev.mybatis.paginator.domain.PageBounds)
	 */
	@Override
	public List getUserList(XueshengDto user, PageBounds pageBounds) {
		// TODO Auto-generated method stub
		return xueshengMapperSql.getUserList(user, pageBounds);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.service.XueshengService#batchDelete(java.lang.String[])
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public int batchDelete(String[] ids) {
		// TODO Auto-generated method stub
		return xueshengMapper.batchDelete(ids);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.caiyigo.zoo.service.XueshengService#getAll()
	 */
	@Override
	public Map<String, Xuesheng> getAll() {
		Map<String, Xuesheng> map = new HashMap<String, Xuesheng>();

		for (Xuesheng x : xueshengMapper.getAll()) {
			map.put(x.getZkz(), x);
		}
		return map;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.caiyigo.zoo.service.XueshengService#batchUpdate(java.util.List)
	 */
	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public boolean batchUpdate(List<Xuesheng> record) {
		// TODO Auto-generated method stub
		return xueshengMapper.batchUpdate(record) > 0;
	}

	@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
	@Override
	public boolean importExcel(List<Xuesheng> updateLIst,
			List<Xuesheng> insertList) {
		// TODO Auto-generated method stub
		return xueshengMapper.batchUpdate(updateLIst) > 0;
	}

	@Override
	public Map<String, Xuesheng> getXueshengForZWCJ(String pici, String type) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("pici", pici);

		if ("zw".equals(type)) {
			params.put("type", "kaoshizw");
		} else if ("cj".equals(type)) {
			params.put("type", "kaoshicj");
		}
		Map<String, Xuesheng> map = new HashMap<String, Xuesheng>();

		for (Xuesheng x : xueshengMapper.getXueshengForZWCJ(params)) {
			map.put(x.getZkz(), x);
		}
		return map;
	}

}
